package com.google.android.material.bottomnavigation;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import androidx.annotation.Dimension;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.annotation.StyleRes;
import androidx.core.view.ViewCompat;
import androidx.transition.AutoTransition;
import androidx.transition.TransitionSet;
import o.ah;
import o.aqu.c;
import o.ar;
import o.asd;
import o.bd;
import o.bj;
import o.bo;
import o.hg.b;
import o.hg.e;
import o.kk;
import o.nr;

@RestrictTo({d.LIBRARY_GROUP})
public class BottomNavigationMenuView extends ViewGroup implements bo {
    private static final int[] ˎ = new int[]{-16842910};
    private static final int[] ˏ = new int[]{16842912};
    private final int ʻ;
    private final ColorStateList ʻॱ;
    private final int ʼ;
    private Drawable ʼॱ;
    private final e<BottomNavigationItemView> ʽ;
    private BottomNavigationPresenter ʽॱ;
    @StyleRes
    private int ʾ;
    private int ʿ;
    private int[] ˈ;
    private final int ˊ;
    private int ˊॱ;
    private bd ˊᐝ;
    private final int ˋ;
    private int ˋॱ;
    private boolean ˏॱ;
    private int ͺ;
    private final TransitionSet ॱ;
    private BottomNavigationItemView[] ॱˊ;
    private ColorStateList ॱˋ;
    @Dimension
    private int ॱˎ;
    private final int ॱॱ;
    @StyleRes
    private int ॱᐝ;
    private final OnClickListener ᐝ;
    private ColorStateList ᐝॱ;

    public BottomNavigationMenuView(Context context) {
        this(context, null);
    }

    public BottomNavigationMenuView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.ʽ = new b(5);
        this.ˊॱ = 0;
        this.ͺ = 0;
        Resources resources = getResources();
        this.ˊ = resources.getDimensionPixelSize(c.ˏ);
        this.ˋ = resources.getDimensionPixelSize(c.ʽ);
        this.ʼ = resources.getDimensionPixelSize(c.ˎ);
        this.ॱॱ = resources.getDimensionPixelSize(c.ˋ);
        this.ʻ = resources.getDimensionPixelSize(c.ॱ);
        this.ʻॱ = ˎ(16842808);
        this.ॱ = new AutoTransition();
        this.ॱ.ˊ(0);
        this.ॱ.ˏ(115);
        this.ॱ.ॱ(new kk());
        this.ॱ.ˋ(new asd());
        this.ᐝ = new OnClickListener(this) {
            final /* synthetic */ BottomNavigationMenuView ˊ;

            {
                this.ˊ = r1;
            }

            public void onClick(View view) {
                MenuItem ˏ = ((BottomNavigationItemView) view).ˏ();
                if (!this.ˊ.ˊᐝ.ˊ(ˏ, this.ˊ.ʽॱ, 0)) {
                    ˏ.setChecked(true);
                }
            }
        };
        this.ˈ = new int[5];
    }

    public void ˎ(bd bdVar) {
        this.ˊᐝ = bdVar;
    }

    protected void onMeasure(int i, int i2) {
        int i3;
        int i4;
        int i5 = 1;
        int size = MeasureSpec.getSize(i);
        int size2 = this.ˊᐝ.ʽ().size();
        int childCount = getChildCount();
        int makeMeasureSpec = MeasureSpec.makeMeasureSpec(this.ʻ, 1073741824);
        if (ˊ(this.ˋॱ, size2) && this.ˏॱ) {
            View childAt = getChildAt(this.ͺ);
            i3 = this.ॱॱ;
            if (childAt.getVisibility() != 8) {
                childAt.measure(MeasureSpec.makeMeasureSpec(this.ʼ, Integer.MIN_VALUE), makeMeasureSpec);
                i3 = Math.max(i3, childAt.getMeasuredWidth());
            }
            i4 = size2 - (childAt.getVisibility() != 8 ? 1 : 0);
            size2 = Math.min(size - (this.ˋ * i4), Math.min(i3, this.ʼ));
            i3 = size - size2;
            if (i4 != 0) {
                i5 = i4;
            }
            i5 = Math.min(i3 / i5, this.ˊ);
            i4 = (size - size2) - (i4 * i5);
            size = 0;
            while (size < childCount) {
                if (getChildAt(size).getVisibility() != 8) {
                    int[] iArr = this.ˈ;
                    if (size == this.ͺ) {
                        i3 = size2;
                    } else {
                        i3 = i5;
                    }
                    iArr[size] = i3;
                    if (i4 > 0) {
                        int[] iArr2 = this.ˈ;
                        iArr2[size] = iArr2[size] + 1;
                        i3 = i4 - 1;
                    }
                    i3 = i4;
                } else {
                    this.ˈ[size] = 0;
                    i3 = i4;
                }
                size++;
                i4 = i3;
            }
        } else {
            if (size2 != 0) {
                i5 = size2;
            }
            i5 = Math.min(size / i5, this.ʼ);
            i3 = size - (i5 * size2);
            for (i4 = 0; i4 < childCount; i4++) {
                if (getChildAt(i4).getVisibility() != 8) {
                    this.ˈ[i4] = i5;
                    if (i3 > 0) {
                        int[] iArr3 = this.ˈ;
                        iArr3[i4] = iArr3[i4] + 1;
                        i3--;
                    }
                } else {
                    this.ˈ[i4] = 0;
                }
            }
        }
        i3 = 0;
        for (i4 = 0; i4 < childCount; i4++) {
            View childAt2 = getChildAt(i4);
            if (childAt2.getVisibility() != 8) {
                childAt2.measure(MeasureSpec.makeMeasureSpec(this.ˈ[i4], 1073741824), makeMeasureSpec);
                childAt2.getLayoutParams().width = childAt2.getMeasuredWidth();
                i3 += childAt2.getMeasuredWidth();
            }
        }
        setMeasuredDimension(View.resolveSizeAndState(i3, MeasureSpec.makeMeasureSpec(i3, 1073741824), 0), View.resolveSizeAndState(this.ʻ, makeMeasureSpec, 0));
    }

    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        int childCount = getChildCount();
        int i5 = i3 - i;
        int i6 = i4 - i2;
        int i7 = 0;
        for (int i8 = 0; i8 < childCount; i8++) {
            View childAt = getChildAt(i8);
            if (childAt.getVisibility() != 8) {
                if (ViewCompat.ʼ(this) == 1) {
                    childAt.layout((i5 - i7) - childAt.getMeasuredWidth(), 0, i5 - i7, i6);
                } else {
                    childAt.layout(i7, 0, childAt.getMeasuredWidth() + i7, i6);
                }
                i7 += childAt.getMeasuredWidth();
            }
        }
    }

    public void setIconTintList(ColorStateList colorStateList) {
        this.ᐝॱ = colorStateList;
        if (this.ॱˊ != null) {
            for (BottomNavigationItemView iconTintList : this.ॱˊ) {
                iconTintList.setIconTintList(colorStateList);
            }
        }
    }

    public void setItemIconSize(@Dimension int i) {
        this.ॱˎ = i;
        if (this.ॱˊ != null) {
            for (BottomNavigationItemView iconSize : this.ॱˊ) {
                iconSize.setIconSize(i);
            }
        }
    }

    public void setItemTextColor(ColorStateList colorStateList) {
        this.ॱˋ = colorStateList;
        if (this.ॱˊ != null) {
            for (BottomNavigationItemView textColor : this.ॱˊ) {
                textColor.setTextColor(colorStateList);
            }
        }
    }

    public void setItemTextAppearanceInactive(@StyleRes int i) {
        this.ॱᐝ = i;
        if (this.ॱˊ != null) {
            for (BottomNavigationItemView bottomNavigationItemView : this.ॱˊ) {
                bottomNavigationItemView.setTextAppearanceInactive(i);
                if (this.ॱˋ != null) {
                    bottomNavigationItemView.setTextColor(this.ॱˋ);
                }
            }
        }
    }

    public void setItemTextAppearanceActive(@StyleRes int i) {
        this.ʾ = i;
        if (this.ॱˊ != null) {
            for (BottomNavigationItemView bottomNavigationItemView : this.ॱˊ) {
                bottomNavigationItemView.setTextAppearanceActive(i);
                if (this.ॱˋ != null) {
                    bottomNavigationItemView.setTextColor(this.ॱˋ);
                }
            }
        }
    }

    public void setItemBackgroundRes(int i) {
        this.ʿ = i;
        if (this.ॱˊ != null) {
            for (BottomNavigationItemView itemBackground : this.ॱˊ) {
                itemBackground.setItemBackground(i);
            }
        }
    }

    public void setItemBackground(@Nullable Drawable drawable) {
        this.ʼॱ = drawable;
        if (this.ॱˊ != null) {
            for (BottomNavigationItemView itemBackground : this.ॱˊ) {
                itemBackground.setItemBackground(drawable);
            }
        }
    }

    public void setLabelVisibilityMode(int i) {
        this.ˋॱ = i;
    }

    public int ॱ() {
        return this.ˋॱ;
    }

    public void setItemHorizontalTranslationEnabled(boolean z) {
        this.ˏॱ = z;
    }

    public boolean ˋ() {
        return this.ˏॱ;
    }

    public ColorStateList ˎ(int i) {
        TypedValue typedValue = new TypedValue();
        if (!getContext().getTheme().resolveAttribute(i, typedValue, true)) {
            return null;
        }
        ColorStateList ˊ = ar.ˊ(getContext(), typedValue.resourceId);
        if (!getContext().getTheme().resolveAttribute(ah.c.ʽॱ, typedValue, true)) {
            return null;
        }
        int i2 = typedValue.data;
        int defaultColor = ˊ.getDefaultColor();
        return new ColorStateList(new int[][]{ˎ, ˏ, EMPTY_STATE_SET}, new int[]{ˊ.getColorForState(ˎ, defaultColor), i2, defaultColor});
    }

    public void setPresenter(BottomNavigationPresenter bottomNavigationPresenter) {
        this.ʽॱ = bottomNavigationPresenter;
    }

    public void ˏ() {
        removeAllViews();
        if (this.ॱˊ != null) {
            for (Object obj : this.ॱˊ) {
                if (obj != null) {
                    this.ʽ.ˋ(obj);
                }
            }
        }
        if (this.ˊᐝ.size() == 0) {
            this.ˊॱ = 0;
            this.ͺ = 0;
            this.ॱˊ = null;
            return;
        }
        this.ॱˊ = new BottomNavigationItemView[this.ˊᐝ.size()];
        boolean ˊ = ˊ(this.ˋॱ, this.ˊᐝ.ʽ().size());
        for (int i = 0; i < this.ˊᐝ.size(); i++) {
            this.ʽॱ.ˎ(true);
            this.ˊᐝ.getItem(i).setCheckable(true);
            this.ʽॱ.ˎ(false);
            View ʼ = ʼ();
            this.ॱˊ[i] = ʼ;
            ʼ.setIconTintList(this.ᐝॱ);
            ʼ.setIconSize(this.ॱˎ);
            ʼ.setTextColor(this.ʻॱ);
            ʼ.setTextAppearanceInactive(this.ॱᐝ);
            ʼ.setTextAppearanceActive(this.ʾ);
            ʼ.setTextColor(this.ॱˋ);
            if (this.ʼॱ != null) {
                ʼ.setItemBackground(this.ʼॱ);
            } else {
                ʼ.setItemBackground(this.ʿ);
            }
            ʼ.setShifting(ˊ);
            ʼ.setLabelVisibilityMode(this.ˋॱ);
            ʼ.ॱ((bj) this.ˊᐝ.getItem(i), 0);
            ʼ.setItemPosition(i);
            ʼ.setOnClickListener(this.ᐝ);
            addView(ʼ);
        }
        this.ͺ = Math.min(this.ˊᐝ.size() - 1, this.ͺ);
        this.ˊᐝ.getItem(this.ͺ).setChecked(true);
    }

    public void ˊ() {
        if (this.ˊᐝ != null && this.ॱˊ != null) {
            int size = this.ˊᐝ.size();
            if (size != this.ॱˊ.length) {
                ˏ();
                return;
            }
            int i = this.ˊॱ;
            for (int i2 = 0; i2 < size; i2++) {
                MenuItem item = this.ˊᐝ.getItem(i2);
                if (item.isChecked()) {
                    this.ˊॱ = item.getItemId();
                    this.ͺ = i2;
                }
            }
            if (i != this.ˊॱ) {
                nr.ˊ(this, this.ॱ);
            }
            boolean ˊ = ˊ(this.ˋॱ, this.ˊᐝ.ʽ().size());
            for (i = 0; i < size; i++) {
                this.ʽॱ.ˎ(true);
                this.ॱˊ[i].setLabelVisibilityMode(this.ˋॱ);
                this.ॱˊ[i].setShifting(ˊ);
                this.ॱˊ[i].ॱ((bj) this.ˊᐝ.getItem(i), 0);
                this.ʽॱ.ˎ(false);
            }
        }
    }

    private BottomNavigationItemView ʼ() {
        BottomNavigationItemView bottomNavigationItemView = (BottomNavigationItemView) this.ʽ.ˎ();
        if (bottomNavigationItemView == null) {
            return new BottomNavigationItemView(getContext());
        }
        return bottomNavigationItemView;
    }

    public int ˎ() {
        return this.ˊॱ;
    }

    private boolean ˊ(int i, int i2) {
        return i == -1 ? i2 > 3 : i == 0;
    }

    void ˊ(int i) {
        int size = this.ˊᐝ.size();
        for (int i2 = 0; i2 < size; i2++) {
            MenuItem item = this.ˊᐝ.getItem(i2);
            if (i == item.getItemId()) {
                this.ˊॱ = i;
                this.ͺ = i2;
                item.setChecked(true);
                return;
            }
        }
    }
}
